<template>
  <div>
    <el-form
      :inline="true"
      :show-message="false"
      :hide-required-asterisk="true"
      :model="membershipCard"
      label-width="90px"
      label-position="right"
    >
      <el-row class="">
        <el-col :span="22">会员卡信息</el-col>
      </el-row>
      <el-divider content-position="center"></el-divider>
      <el-row>
        <el-col :span="6" v-if="!isEdit">
          <el-form-item  label="会员卡编号:">
            <div>{{ membershipCard.memberCode }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="会员名称:">
            <div>{{ membershipCard.clientName }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="会员等级:">
            <div>{{ membershipCard.memberLevelDictValue }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="!isEdit">
          <el-form-item label="会员到期:">
            <div>{{ membershipCard.validDate }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="!isEdit">
          <el-form-item label="会员积分:">
            <div>{{ membershipCard.integral1 }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="!isEdit">
          <el-form-item label="配件折扣:">
            <div>{{ membershipCard.partsDiscount }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="!isEdit">
          <el-form-item label="工时折扣:">
            <div>{{ membershipCard.hoursDiscount }}</div>
          </el-form-item>
        </el-col>
         <el-col :span="6" v-if="isEdit">
          <el-form-item label="配件折扣:">
            <div>{{ membershipCard.partsDiscount }}</div>
          </el-form-item>
        </el-col>
         <el-col :span="6" v-if="isEdit">
          <el-form-item label="工时折扣:">
            <div>{{ membershipCard.hoursDiscount }}</div>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="6" v-if="isEdit">
          <el-form-item label="有效期:">
            <div>{{ membershipCard.validDate }}</div>
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-form>

    <el-row class="">
      <el-col :span="22">会员卡权益列表</el-col>
    </el-row>
    <el-divider content-position="center"></el-divider>
    <el-row>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        :has-action="isEdit"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="权益"

            style="margin-left: 20px; cursor: pointer"
            @click="interestsAdd(row)"
          ></i>
        </template>
      </data-table>
    </el-row>
  </div>
</template>

<script>
import { findMemberById } from '@/api/after-sale/client/client'
import { equitiesPage } from '@/api/after-sale/client/level'
import baseMixin from '@/mixins/base'
import {
  memberdetail,
} from '@/api/after-sale/client/level'
// import { parseTimeToYMDHMS } from '@/utils'

export default {
  name: 'carInfo',
  components: {},
  props: {
    fromdata: {
      type: Object,
      default: () => ({}),
    },
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  mixins: [
    baseMixin({
      findData: equitiesPage,
      dataName: ['content', 'totalRecords'],
      format(res) {
        return res.map((data) => {
          return data
        })
      },
    }),
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: '权益名称', value: 'equitiesName', type: 'text' },
        { name: '权益内容', value: 'equitiesDesc', type: 'text' },
        { name: '权益介绍', value: 'equitiesText', type: 'renderHtml',},
      ],
      rules: [],
      membershipCard: {
        memberCode: '', //会员卡编号
        name: '', //会员名称
        memberLevelDictValue: '', //会员等级
        integral1: '', //会员积分
        partsDiscount: '', //配件折扣
        hoursDiscount:'',//工时折扣
        validDate:'',//有效期
      }, //会员卡信息
    }
  },
  async created() {
    this.notQuery = true
    if (!this.isEdit&&this.fromdata.id) {
      //根据客户ID查询会员卡
      findMemberById(this.fromdata.id).then((res) => {
        let { success, data } = res
        if (success) {
          this.membershipCard = data
          this.searchOptions.memberId = data.id
          this.notQuery = false
          this._getMemberdetail(data.id)
          this.setTableData()
        }
      })
    }else{
      this._getMemberdetail(this.fromdata.id);
    }

  },
  methods: {
    _getMemberdetail(id){
 //查询会员卡详情
      memberdetail(id).then(res=>{
        let { success, data } = res
        if (success) {
          this.membershipCard ={...this.membershipCard,...data}
          this.searchOptions.memberId = data.id
          this.notQuery = false
          this.setTableData()
        }
      })
    },

    interestsAdd(row) {
      this.$emit('operate', row)
    },
    changeType(item) {
      this.selectedTypeText = item.label
    },
  },
  mounted() {},
}
</script>

<style lang="scss" scoped>
.el-table .delete-row {
  background: #f5f7fa;
  color: #ccc !important;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 80px;
  height: 80px;
  display: block;
}
</style>
